<?php
	class productVote
	{	
		function show_product_vote()
		{
			$data = new database();		
			$sql="	select *
					from tblproduct, tblproductVote,tblproductoption 
					where tblproductoption.optionID=tblproductvote.optionID 
						and tblproduct.productID = tblproductVote.productID";
			$data->SetQuery($sql);
			$table = $data->LoadAllRow();
			$data->disconnect();
			return $table;	
		}
		function insert_product_vote($optionID, $productID, $ipAddress, $voteTime)
		{
			$data = new database();		
			$sql="INSERT INTO tblproductvote (optionID,productID,ipAddress,voteTime)
			       	VALUES({$optionID},{$productID},'{$ipAddress}','{$voteTime}')";
		
			$data = new database();
			$data->SetQuery($sql);
			$data->Query();
			$data->disconnect();	
		}
		
		function count_product_vote_by_proID_and_title($productID, $title)
		{
			$data = new database();	
			
				$sql="	SELECT COUNT(tblproductvote.optionID) as total,tblproductoption.title 
						FROM tblproduct,tblproductoption, tblproductvote 
						where tblproduct.productID = tblproductvote.productID 
							and tblproductoption.optionID = tblproductvote.optionID
							and tblproductvote.productID='{$productID}' 
							AND tblproductoption.title='{$title}'";

			$data->SetQuery($sql);
			$table = $data->LoadOneRow();
			$data->disconnect();
			if(count($table) > 0)
			{
				return $table;
			}
			else 
			{
				return false;
			}		
		}
		function count_product_vote_by_proID_and_title_and_date($productID, $title, $date)
		{
			$data = new database();	
			
				$sql="	SELECT COUNT(tblproductvote.optionID) as total,tblproductoption.title,tblproductvote.voteTime
						FROM tblproduct,tblproductoption, tblproductvote 
						where tblproduct.productID = tblproductvote.productID 
						and tblproductoption.optionID = tblproductvote.optionID 
						and tblproductvote.productID='{$productID}' 
						and date(tblproductvote.voteTime)=STR_TO_DATE('$date','%m-%d-%Y')
						AND tblproductoption.title='{$title}'";

			$data->SetQuery($sql);
			$table = $data->LoadOneRow();
			$data->disconnect();
			if(count($table) > 0)
			{
				return $table;
			}
			else 
			{
				return false;
			}		
		}
		
		function count_product_vote_by_proID($productID)
		{
			$data = new database();	
			
				$sql="	SELECT COUNT(tblproductvote.optionID) as total,tblproductoption.title 
						FROM tblproduct,tblproductoption, tblproductvote 
						where tblproduct.productID = tblproductvote.productID 
							and tblproductoption.optionID = tblproductvote.optionID
							and tblproductvote.productID='{$productID}'";

			$data->SetQuery($sql);
			$table = $data->LoadOneRow();
			$data->disconnect();
			if(count($table) > 0)
			{
				return $table;
			}
			else 
			{
				return false;
			}		
		}
		
		function show_product_vote_by_proID_and_date($productID)
		{
			$data = new database();	
			
				$sql="	SELECT tblproductvote.voteTime FROM tblproductvote
						where tblproductvote.voteTime = (	SELECT max(tblproductvote.voteTime) 
															FROM tblproductvote 
															WHERE tblproductvote.productID ={$productID} 
															ORDER BY voteID DESC 
															LIMIT 0,1)
						AND tblproductvote.productID =".$productID;

			$data->SetQuery($sql);
			$table = $data->LoadOneRow();
			$data->disconnect();
			if(count($table) > 0)
			{
				return $table;
			}
			else 
			{
				return false;
			}		
		}
		
		
	}
?>